package nanocast.apps.creator.modules.sceneListModule.view
{
	import org.puremvc.as3.multicore.interfaces.INotification;	import org.puremvc.as3.multicore.utilities.pipes.interfaces.IPipeFitting;	import org.puremvc.as3.multicore.utilities.pipes.interfaces.IPipeMessage;	import org.puremvc.as3.multicore.utilities.pipes.messages.Message;	import org.puremvc.as3.multicore.utilities.pipes.plumbing.Junction;	import org.puremvc.as3.multicore.utilities.pipes.plumbing.JunctionMediator;	import org.puremvc.as3.multicore.utilities.pipes.plumbing.TeeMerge;	import org.puremvc.as3.multicore.utilities.pipes.plumbing.TeeSplit;		import nanocast.apps.creator.common.PipeAwareModuleConstants;	
	public class SceneListJunctionMediator extends JunctionMediator
	{
		public static const NAME:String = "SceneListJunctionMediator";
		
		public function SceneListJunctionMediator()
		{
			super(NAME, new Junction());
		}
		
		override public function onRegister():void
		{
			junction.registerPipe(PipeAwareModuleConstants.IN_PIPE,Junction.INPUT, new TeeMerge());
			junction.registerPipe(PipeAwareModuleConstants.OUT_PIPE, Junction.OUTPUT, new TeeSplit());
			
			junction.addPipeListener(PipeAwareModuleConstants.IN_PIPE, this, handlePipeMessage);
		}
		
		override public function onRemove():void
		{
			
		}
		
		override public function listNotificationInterests():Array
		{
			var interests:Array = super.listNotificationInterests();
			interests.push(PipeAwareModuleConstants.MODULE_TO_SHELL_MESSAGE);
			return interests;
		}
		
		override public function handleNotification(note:INotification):void
		{
			switch(note.getName())
			{	
				case JunctionMediator.ACCEPT_INPUT_PIPE:
						var inPipe:TeeMerge = junction.retrievePipe(PipeAwareModuleConstants.IN_PIPE) as TeeMerge;
						inPipe.connectInput(note.getBody()as IPipeFitting);
						break;
						
				case JunctionMediator.ACCEPT_OUTPUT_PIPE:
						var outputPipe:TeeSplit = junction.retrievePipe(PipeAwareModuleConstants.OUT_PIPE) as TeeSplit;
						outputPipe.connect(note.getBody() as IPipeFitting);
						break;
						
				case PipeAwareModuleConstants.MODULE_TO_SHELL_MESSAGE:
					trace("note_body : ",  note.getBody());
					junction.sendMessage(PipeAwareModuleConstants.OUT_PIPE, new Message(PipeAwareModuleConstants.MODULE_TO_SHELL_MESSAGE,null,note.getBody()));
					break;
					
				default:
					super.handleNotification(note);
			}		
		}
		
		override public function handlePipeMessage(message:IPipeMessage):void
		{
			switch(message.getType()) 
			{
				default:
					trace("debug --> message type " + message.getType() + "message body " + message.getBody());		 
			}
		}
		
		
		
	}
}